package org.jsets.fastboot.oss.mapper;

import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.jsets.fastboot.oss.model.dto.BucketQuery;
import org.jsets.fastboot.oss.model.entity.Bucket;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

@Mapper
public interface BucketMapper extends BaseMapper<Bucket> {

	
    /**
     * 分页查询
     * @param page 分页参数
     * @param criteria 查询条件
     * @return List<TimerTaskLog>
     */
	 @Select( "<script>"
            + "  select  "
            + "  t.id,t.name,t.exclude_type,t.noticeable,t.remark,t.create_time,t.storage_id  "
            + "	 ,s.name as storage_name  "
            + "  ,(select count(id) as count from sys_file_meta where bucket_name = t.name) as file_count "
            + "  from sys_oss_bucket t  "
            + "  join sys_oss_storage s on s.id = t.storage_id  "
            + "  <where>  "
            + "    <if test='criteria.name != null and criteria.name != \"\"'>  "
            + "      t.name like concat('%',#{criteria.name},'%')  "
            + "    </if>  "
            + "    <if test='criteria.storageId != null and criteria.storageId != \"\"'>  "
            + "      t.storage_id like concat('%',#{criteria.storageId},'%')  "
            + "    </if>  "
            + "  </where>  "
            + "  order by t.create_time desc  "
            + "</script>  ")                   
    List<Bucket> selectPage(Page<Bucket> page, @Param("criteria") BucketQuery criteria);
}